$(document).ready(
    function() {
        bindProduceStatsChartEvents();

        $('#appStorehouseMenuTabs').trigger("tabsload");   // inform tabs event listener
//        wacDebugLog("trigger: tabsload");
    }
    );

function bindProduceStatsChartEvents()
{
    $('#btn_produce_stats_chart').bind(
        'click',
        function (e)
        {
            getProduceStatsChart();
        }
        );

    $("select[name*=produce_stats_chart]").bind(
        'change',
        function (e)
        {
            getProduceStatsChart();
        }
        );

//    $("#produce_stats_chart_from_year, #produce_stats_chart_from_month, #produce_stats_chart_from_day, #produce_stats_chart_to_year, #produce_stats_chart_to_month, #produce_stats_chart_to_day").bind(
//        'change',
//        function (e)
//        {
//            getProduceStatsChart();
//        }
//        );


}

function getProduceStatsChart()
{
    var params = {};
    var errCode = 0;

    params.data_module  = 'statistic';
    params.data_action  = 'getProduceStatsChartData';
    params.chart_type  = 'stBar3D';
    params.swf_width  = '800';
    params.swf_height  = '400';
    params.start_day   = Number($("#produce_stats_chart_from_day").val());
    params.start_month = Number($("#produce_stats_chart_from_month").val());
    params.start_year  = Number($("#produce_stats_chart_from_year").val());
    params.end_day     = Number($("#produce_stats_chart_to_day").val());
    params.end_month   = Number($("#produce_stats_chart_to_month").val());
    params.end_year    = Number($("#produce_stats_chart_to_year").val());

    if(params.start_year > params.end_year)
    {
        errCode = 1;
    }
    else
    {
        if((params.start_year==params.end_year) && (params.start_month > params.end_month))
        {
            errCode = 2;
        }
        else
        {
            if((params.start_year==params.end_year) && (params.start_month==params.end_month) && (params.start_day > params.end_day))
            {
                errCode = 3;
            }

        }
    }
//    wacDebugLog(params);
    if(errCode>0){
//        wacDebugLog(errCode);
        wacShowTips("查询开始时间必须要小于或等于截止时间!");
        return false;
    }

    $.getJSON(
        BASE_URL+"statistic/getStatsChart",
        //            BASE_URL+"statistic/ajaxTest",
        params,
        function(jsonData){
            getProduceStatsChartCallBack(jsonData);
        }
        );

   return true;
}

function getProduceStatsChartCallBack(jsonData)
{
    $("#produce_stats_chart")[0].innerHTML = jsonData['items'][0].content;
//    $("#debug_div")[0].innerHTML = jsonData['items'][0].content;
}



